package com.devunion.reader.client.core;

import com.google.gwt.user.client.ui.*;

/**
 * Should be used while making rpc calls to server.
 *
 * @author spetrakovsky
 */
public class Loading extends DialogBox {

	/**
	 * Component content.
	 */
	private HorizontalPanel content = new HorizontalPanel();

	/**
	 * Loading image.
	 */
	private Image loadingImage = new Image("images/loading.gif");

	/**
	 * Loading label.
	 */
	private Label loadingLabel = new Label();

	/**
	 * Constructor.
	 */
	public Loading() {
		this("Loading...");
	}

	/**
	 * Constructor.
	 */
	public Loading(String text) {
		loadingLabel.setText(text);
		setStyles();
		buildLayout();
	}

	/**
	 * Showing component in the center of the screen.
	 */
	public void showLoading() {
		center();
		show();
	}

	/**
	 * Sets component styles.
	 */
	private void setStyles() {
		content.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		content.setSpacing(5);
		addStyleName("loadingStatus");
		removeStyleName("gwt-DialogBox");
	}

	/**
	 * Builds component layout.
	 */
	private void buildLayout() {
		content.add(loadingImage);
		content.add(loadingLabel);
		add(content);
	}
}
